package Reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by wangyg 
 * on 2017/7/9 11:21
 */
public class Test {
	public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException,
			InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
		Class<?> clz = Class.forName("Reflection.SimpleClass");
		Constructor<?> cons = clz.getDeclaredConstructor(Long.class);
		//		SimpleClass simpleClass = (SimpleClass) clz.newInstance();
		cons.setAccessible(true);
		SimpleClass simpleClass = (SimpleClass) cons.newInstance(123L);

		simpleClass.doSth();

		Field arg = clz.getDeclaredField("arg");
		arg.setAccessible(true);
		Object o = arg.get(simpleClass);
		System.out.println(o+":");
		arg.set(simpleClass,"this is arg");
		Object o1 = arg.get(simpleClass);
		System.out.println(o1);

	}
}
